package np13.utils;

/**
 * 
 * Helper-class for the simulation. ThreadUnsafe.
 */
public class Simulate {

	/**
	 * Core size of the split-worker pool.
	 */
	public static int splitWorkerPoolCore = 8;
	/**
	 * Max size of the split-worker pool.
	 */
	public static int splitWorkerPoolMax = 256;
	/**
	 * Core size of the post-worker pool.
	 */
	public static int postWorkerPoolCore = 4;
	/**
	 * Max size of the post-worker pool.
	 */
	public static int postWorkerPoolMax = 64;

	/**
	 * Is the hardware-interrupt enabled.
	 */
	public static boolean isHWInterruptEnabled;

	/**
	 * Hardware-interrupt (10 ms)
	 */
	public static void HWinterrupt() {

		if (isHWInterruptEnabled)
			HWinterrupt(10);
	}

	/**
	 * hardware-interrupt
	 * 
	 * @param ms
	 *            milliseconds
	 */
	public static void HWinterrupt(int ms) {
		if (!isHWInterruptEnabled)
			return;
		try {
			Thread.sleep(ms);
			Console.printlnWithForce("HW");
		} catch (InterruptedException e) {

			Console.printlnWithForce("HWE");
			Thread.currentThread().interrupt();
			e.printStackTrace();
		}
	}

	/**
	 * Initializes the Core/Max-values of the worker-pools, those values depend
	 * on the number of available processor.
	 */
	public static void initPool() {

		Runtime runtime = Runtime.getRuntime();
		int numberProcessors = runtime.availableProcessors();
		Console.println("# processors: " + numberProcessors);

		splitWorkerPoolCore = 2 * numberProcessors;
		splitWorkerPoolMax = 64 * numberProcessors;
		postWorkerPoolCore = 1 * numberProcessors;
		postWorkerPoolMax = 16 * numberProcessors;
	}

}
